<template>
  <a-card :bordered="false">
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" v-show="activeKey == 'cg'" @click="addNotice" icon="plus" style="margin-left: 8px"
        >添加入库单</a-button
      >
      <a-button @click="handleAdd" v-show="activeKey == 'rk'" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('入库通知单')">导出</a-button>
      <!--      <a-button type="primary" icon="download" @click="alert('打印预览')">打印预览</a-button>-->
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->
      <!--      <a-button type="primary" @click="reverseCheck">-->
      <!--        <a-icon type="close" /> 撤销审核-->
      <!--      </a-button>-->
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>
    <a-tabs v-model="activeKey" @change="handleChangeTab">
      <a-tab-pane key="cg" tab="采购订单">
        <div>
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
              <a-row :gutter="24">
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <a-form-item label="">
                    <a-input v-model="ext" :allow-clear="true"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :xl="6" :lg="7" :md="8" :sm="24">
                  <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                    <a-button type="primary" @click="searchQueryTab1" icon="search">搜索</a-button>
                  </span>
                </a-col>
              </a-row>
            </a-form>
          </div>
          <a-table
            ref="procTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="table1.columns"
            :dataSource="table1.dataSource"
            :pagination="table1.ipagination"
            :loading="table1.loading"
            :rowSelection="{ selectedRowKeys: table1.selectedRowKeys, onChange: onSelectChangeTab1 }"
            :customRow="rowProperties"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
          </a-table>
        </div>
      </a-tab-pane>
      <a-tab-pane key="rk" tab="入库单" force-render>
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row>
              <a-col :xl="4" :lg="4" :md="4" :sm="4">
                <a-form-item label="">
                  <a-radio-group v-model="queryParam.status" @change="onRadioChange">
                    <a-radio :value="0">已审批</a-radio>
                    <a-radio :value="1">需修改</a-radio>
                    <a-radio :value="2">入库完成</a-radio>
                  </a-radio-group>
                </a-form-item>
              </a-col>
              <a-col :xl="4" :lg="6" :md="6" :sm="6">
                <a-form-item label="起始日期">
                  <a-date-picker
                    type="ge"
                    v-model="queryParam.createTime_begin"
                    :format="dateFormat"
                    :valueFormat="dateFormat"
                    @change="changeDate"
                  />
                </a-form-item>
              </a-col>
              <a-col :xl="4" :lg="7" :md="8" :sm="24">
                <a-form-item label="截止日期">
                  <a-date-picker
                    type="le"
                    v-model="queryParam.createTime_end"
                    :format="dateFormat"
                    :valueFormat="dateFormat"
                    @change="changeDate"
                  />
                </a-form-item>
              </a-col>
              <a-col :xl="2" :lg="7" :md="8" :sm="24">
                <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <!-- <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->
                  <!-- <a @click="handleToggleSearch" style="margin-left: 8px">-->
                  <!-- {{ toggleSearchStatus ? '收起' : '展开' }}-->
                  <!-- <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
                  <!-- </a>-->
                </span>
              </a-col>
              <a-col style="float: left" :xl="10">
                <tsl-simple-query
                  :data-source="dataSource"
                  :columns="columns"
                  @searchQueryTab="searchQueryTab"
                  @clearQueryTab="clearQueryTab"
                  @initQueryColumns="initQueryColumns"
                ></tsl-simple-query>
              </a-col>
            </a-row>
          </a-form>
        </div>

        <div>
          <TslSettingCloumns
            :selectedRowKeys="selectedRowKeys"
            :settingColumns="settingColumns"
            :defColumns="defColumns"
            @onColSettingsChange="onColSettingsChange"
            @onClearSelected="onClearSelected"
          ></TslSettingCloumns>
          <a-table
            ref="table"
            size="middle"
            bordered
            :rowKey="
              (record, index) => {
                return record.detailId
              }
            "
            class="j-table-force-nowrap1"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :maxHeight="50"
            :scroll="{ x: true }"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
            :customRow="orderRowProperties"
            :rowClassName="(record, index) => (record.qcStatus == 2 ? 'qc' : null)"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
          </a-table>
        </div>
        <a-tabs>
          <a-tab-pane key="detail" tab="物料详情">
            <a-table
              ref="table"
              size="middle"
              bordered
              :rowKey="
                (record, index) => {
                  return record.detailId
                }
              "
              class="j-table-force-nowrap1"
              :columns="noticeDetailsTable.columns"
              :dataSource="noticeDetailsTable.dataSource"
              :loading="loading"
              :scroll="{ x: true }"
              :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
              @change="handleTableChange"
              :customRow="rowProperties"
              :rowClassName="(record, index) => (record.qcStatus == 2 ? 'qc' : null)"
            >
              <template slot="htmlSlot" slot-scope="text">
                <div v-html="text"></div>
              </template>
            </a-table>
          </a-tab-pane>
        </a-tabs>
      </a-tab-pane>
    </a-tabs>

    <!-- table区域-begin -->
    <buss-storage-package-modal ref="modalForm" :containDelete="containDelete" @ok="modalFormOk" />
    <tsl-wm-barcode-list-modal-vue ref="barcodeListForm" @ok="barcodeListFormOk" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import BussStoragePackageModal from './modules/BussStoragePackageModal'
import '@/assets/less/TableExpand.less'
// import { getDictItems } from '@comp/dict/JDictSelectUtil'
import { filterDictTextByCache, filterMultiDictText, getDictItems } from '@/components/dict/JDictSelectUtil'
import { deleteAction, getAction, putAction, postAction } from '@api/manage'
import { filterObj } from '@/utils/util'
import store from '@/store'
import ActApplyBtn from '@views/flowable/components/ActApplyBtn.vue'
import ActHistoricDetailBtn from '@views/flowable/components/ActHistoricDetailBtn.vue'
import ActCancelBtn from '@views/flowable/components/ActCancelBtn'
import ActHandleBtn from '@views/flowable/components/ActHandleBtn'
import moment from 'dayjs'
import TslSettingCloumns from '@comp/tsl/TslSettingCloumns.vue'
import TslSimpleQuery from '@comp/tsl/TslSimpleQuery.vue'
import TslWmBarcodeListModalVue from '../barcode/TslWmBarcodeListModal.vue'

export default {
  name: 'BussStoragePackageList',
  mixins: [JeecgListMixin],
  components: {
    ActHistoricDetailBtn,
    ActApplyBtn,
    BussStoragePackageModal,
    ActCancelBtn,
    ActHandleBtn,
    TslSettingCloumns,
    TslSimpleQuery,
    TslWmBarcodeListModalVue,
  },
  data() {
    return {
      moment,
      //最后一次点击的订单id,用于在生成条码后刷新物料详情列表
      lastClickOrderId: '',
      disableMixinCreated: true,
      isOpenSettingColumns: true,
      dateFormat: 'YYYY-MM-DD',
      barcodeType: 'ORI_',
      containDelete: false,
      //moment(JSON.parse(item.afterContent).updateTime).format('YYYY-MM-DD HH:mm:ss')
      dict: {
        rkType: [],
        unit: [],
      },
      queryParam: {
        status: 0,
      },
      pcaData: '',
      serviceName: 'bussStoragePackageServiceImpl',
      description: '入库通知单管理页面',
      ext: '',
      ext1: '',
      activeKey: 'rk',

      noticeDetailsTable: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '物料编号',
            align: 'center',
            dataIndex: 'materialCode',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'materialName',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '规格',
            align: 'center',
            dataIndex: 'spec',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '库位名称',
            align: 'center',
            dataIndex: 'erpLocationName',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '生产车间',
            align: 'center',
            dataIndex: 'workshopName',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '原发数量',
            align: 'center',
            dataIndex: 'originalNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '实收数量',
            align: 'center',
            dataIndex: 'actualNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '批次号',
            align: 'center',
            dataIndex: 'batchNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '物料批号',
            align: 'center',
            dataIndex: 'materialLotNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '客户物料编号',
            align: 'center',
            dataIndex: 'customerMaterialNo',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '生产日期',
            align: 'center',
            dataIndex: 'createDate',
            scopedSlots: { customRender: 'htmlSlot' },
          },

          {
            title: '限用日期',
            align: 'center',
            dataIndex: 'expiryDate',
            scopedSlots: { customRender: 'htmlSlot' },
          },

          {
            title: '采购数量',
            align: 'center',
            dataIndex: 'procurementNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '已到货数量',
            align: 'center',
            dataIndex: 'arrivalNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },

          {
            title: '单位',
            key: 'meUnit',
            width: '70px',
            dataIndex: 'sysOrgCode_dictText',
            // disabled: true
          },
          {
            title: '供应商',
            key: 'supplierName',
            width: '200px',
            dataIndex: 'supplierName',
            slotName: 'supplierName',
          },
          {
            title: '采购订单编号',
            key: 'procurementCode',
            width: '120px',
            dataIndex: 'procurementCode',
          },
          {
            title: '排产单号',
            key: 'schedulingCode',
            width: '120px',
            dataIndex: 'schedulingCode',
          },

          {
            title: '辅助数量',
            key: 'supportNum',
            width: '120px',
            dataIndex: 'supportNum',
          },
          {
            title: '辅助单位',
            key: 'supportUnit',
            width: '70px',
            dataIndex: 'supportUnit',
          },
          {
            title: '当前状态',
            key: 'status',
            width: '70px',
            placeholder: '请输入${title}',
            defaultValue: '',
            dataIndex: 'status_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 150,
            customRender: (text, record, index) => {
              const obj = {
                children: [
                  //record.status === 0 || record.status === 2
                  record.barcode != null && <a onClick={() => this.getBarcodeEntityByCode(record)}>补打条码</a>,
                  record.barcode != null && <a-divider type="vertical"></a-divider>,
                  record.barcode == null && <a onClick={() => this.generateBarCode(record)}>生成条码</a>,
                  record.barcode == null && <a-divider type="vertical"></a-divider>,
                  <a onClick={() => this.barcodeListFormOpen(record)}>查看详情</a>,
                ],
                attrs: {},
              }

              return obj
            },
            // scopedSlots: { customRender: 'action' },
          },
        ],
        dataSource: [],
        dataSourceBack: [],
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },

      table1: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '编号',
            align: 'center',
            dataIndex: 'code',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '物料编号',
            align: 'center',
            dataIndex: 'materialCode',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '物料名称',
            align: 'center',
            dataIndex: 'materialName',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '规格',
            align: 'center',
            dataIndex: 'spec',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '订单数量',
            align: 'center',
            dataIndex: 'procurementNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '已到货数量',
            align: 'center',
            dataIndex: 'arrivalNum',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '未到货数量',
            align: 'center',
            dataIndex: 'originalNum',
            // scopedSlots: { customRender: 'htmlSlot' },
            customRender: (text, record, index) => {
              // Provide default value if baseValue is missing
              if (record.arrivalNum) {
                return record.procurementNum - record.arrivalNum
              }
              return record.procurementNum
            },
          },
          {
            title: '价格',
            align: 'center',
            dataIndex: 'procurementArrayPrice',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy',
            scopedSlots: { customRender: 'htmlSlot' },
          },
          {
            title: '制单日期',
            align: 'center',
            dataIndex: 'createTime',
            scopedSlots: { customRender: 'htmlSlot' },
          },
        {
          title: '制单部门',
          align: 'center',
          dataIndex: 'sysOrgCode_dictText',
        },
          {
            title: '供方单位',
            align: 'center',
            dataIndex: 'supplierName',

            scopedSlots: { customRender: 'htmlSlot' },
          },
        ],
        dataSource: [],
        dataSourceBack: [],
        ipagination: {
          current: 1,
          pageSize: 30,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      isorter: {
        column: 'id',
        order: 'desc',
      },
      // 表头
      // columns: [],
      settingColumns: [],
      // 表头 defColumns
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '编号',
          align: 'center',
          dataIndex: 'code',
          customRender: (text, record, index) => {
            const sanitizedText = this.sanitizeHTML(text)
            const obj = {
              children: [
                h('div', {
                  domProps: {
                    innerHTML: text, // 直接使用 HTML 字符串
                  },
                }),
              ],
              attrs: {},
            }
            // 判断是否需要合并行
            if (index > 0 && record.id === this.dataSource[index - 1].id) {
              obj.attrs.rowSpan = 0
            } else {
              obj.attrs.rowSpan = this.dataSource.filter((item) => item.id === record.id).length
            }
            return obj
          },
        },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'supplierName',
        },
        {
          title: '批次号',
          align: 'center',
          dataIndex: 'batchNum',
        },
        {
          title: '原料编号',
          align: 'center',
          dataIndex: 'materialCode',
        },
        {
          title: '原料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '规格',
          align: 'center',
          dataIndex: 'spec',
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit_dictText',
        },
        {
          title: '采购数量',
          align: 'center',
          dataIndex: 'procurementNum',
        },
        {
          title: '实收数量',
          align: 'center',
          dataIndex: 'actualNum',
        },
        {
          title: '制单日期',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '制单人',
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: '进厂日期',
          align: 'center',
          dataIndex: 'warehouseDate',
        },
        {
          title: '生产日期',
          align: 'center',
          dataIndex: 'createDate',
        },
        {
          title: '限用日期',
          align: 'center',
          dataIndex: 'expiryDate',
        },
        // {
        //   title:'让步接受数量-',
        //   align:"center",
        //   dataIndex: '',
        //   scopedSlots: { customRender: 'htmlSlot' },
        // },
        // {
        //   title:'入库数量-',
        //   align:"center",
        //   dataIndex: '',
        //   scopedSlots: { customRender: 'htmlSlot' },
        // },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'materialLotNum',
        },
        {
          title: '库位',
          align: 'center',
          dataIndex: 'erpLocationName',
        },
        {
          title: '宝洁供应商编号',
          align: 'center',
          dataIndex: 'bjSupplierCode',
        },
        {
          title: '宝洁供应商采购订单号',
          align: 'center',
          dataIndex: 'bjProcurementCode',
        },
        {
          title: '宝洁供应商名称',
          align: 'center',
          dataIndex: 'bjSupplierName',
        },
        {
          title: '质检状态',
          align: 'center',
          dataIndex: 'qcStatus_dictText',
          // customRender: (text, record, index) => {
          //   if(text == '0'){
          //     return '待质检'
          //   }
          //   return text;
          // }
        },
        {
          title: '质检单号',
          align: 'center',
          dataIndex: 'inspectionCode',
        },
        // {
        //   title: '流程状态',
        //   align: 'center',
        //   dataIndex: 'actStatus',
        // },
        // {
        //   title: '待处理节点',
        //   align: 'center',
        //   dataIndex: 'todoUsers',
        // },
        // {
        //   title:'处理人',
        //   align:"center",
        //   dataIndex: 'todoUsers'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 150,
          customRender: (text, record, index) => {
            const obj = {
              children: [
                //record.status === 0 || record.status === 2
                record.status == 1 && record.qcStatus == 0 && <a onClick={() => this.handleEdit(record)}>编辑</a>,
                record.status == 1 && record.qcStatus == 0 && <a-divider type="vertical"></a-divider>,
                // ( (( record.status == 0) && (record.qcStatus === 0)) || (record.storageType == 1) || ( record.status == 2))  && (
                // <a onClick={() => this.retract(record)}>撤回</a>
                // ),
                // (( record.status == 0) && (record.qcStatus === 0 ) || (record.storageType == 1) || ( record.status == 2))  && (
                // <a-divider type='vertical' />
                // ),
                ((record.status == 0 && record.qcStatus == 0) || (record.status == 2 && record.storageType == 1)) && (
                  <a onClick={() => this.retract(record)}>撤回</a>
                ),
                ((record.status == 0 && record.qcStatus == 0) || (record.status == 2 && record.storageType == 1)) && (
                  <a-divider type="vertical" />
                ),
                <a-dropdown>
                  <a class="ant-dropdown-link">
                    更多 <a-icon type="down" />
                  </a>
                  <a-menu slot="overlay">
                    <a-menu-item>
                      <a onClick={() => this.handleDetail(record)}>详情</a>
                    </a-menu-item>
                    <a-menu-item>
                      <a-popconfirm title="确定删除吗?" onConfirm={() => this.handleDelete(record.id)}>
                        <a>删除</a>
                      </a-popconfirm>
                    </a-menu-item>
                  </a-menu>
                </a-dropdown>,
              ],
              attrs: {},
            }
            // // 判断是否需要合并行
            if (index > 0 && record.id === this.dataSource[index - 1].id) {
              obj.attrs.rowSpan = 0
            } else {
              obj.attrs.rowSpan = this.dataSource.filter((item) => item.id === record.id).length
            }
            return obj
          },
          // scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/business/bussStoragePackage/list',
        delete: '/business/bussStoragePackage/delete',
        deleteBatch: '/business/bussStoragePackage/deleteBatch',
        exportXlsUrl: '/business/bussStoragePackage/exportXls',
        importExcelUrl: 'business/bussStoragePackage/importExcel',
        proclist: '/business/bussMaterialProcurement/page/list',
        bussStoragePackageMaterial: {
          list: '/business/bussStoragePackage/queryBussStoragePackageMaterialByMainId',
        },
        setBarCode: '/business/bussStoragePackage/editAndSaveBarCode',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.columns = this.defColumns
    this.getSuperFieldList()
    // getDictItems('rk_type').then(res=>{
    //   this.dict.rkType = res
    // });
    // getDictItems('zl_unit').then(res=>{
    //   this.dict.unit = res
    // });
    this.loadProcData()
    this.queryParam.createTime_begin = moment().subtract(7, 'days').format(this.dateFormat)
    this.queryParam.createTime_end = moment().format(this.dateFormat)
    this.loadData()
    //初始化字典配置 在自己页面定义
    this.initDictConfig()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    mappeddDataSource() {
      return this.dataSource.map((data) => ({
        ...data,
        type_dictText: data.type ? this.dict.rkType[data.type].label : '',
        // unit_dict: data.unit?this.dict.unit[data.unit].label:""
        // statusText: statusDict[data.status]
      }))
    },
  },
  methods: {
    //查看条码生成列表
    barcodeListFormOpen(record) {
      console.log('查看详情barcode')
      console.log(record)
      console.log('---------------------------')
      this.$refs.barcodeListForm.barcode = record.barcode
      this.$refs.barcodeListForm.code = record.noticeCode
      this.$refs.barcodeListForm.materialId = record.materialId
      this.$refs.barcodeListForm.batch = record.batchNum
      this.$refs.barcodeListForm.procurementDetailId = record.procurementDetailId
      this.$refs.barcodeListForm.arrivalNum = record.arrivalNum

      this.$refs.barcodeListForm.putBarcode()
    },
    //查看条码生成列表关闭
    barcodeListFormOk(record) {
      this.$refs.barcodeListForm.visible = false
    },
    //生成条码并保存
    generateBarCode(record) {
      let param = { type: this.barcodeType }
      console.log(record.id)
      postAction('/sys/fillRule/executeRuleByCode/storage_package_barcode', {}).then((res) => {
        if (res.success) {
          putAction(this.url.setBarCode, { id: record.id, barcode: res.result,materialId:record.materialId }).then((res) => {
            let id = res.result.id
            this.showBarcode(id)
            this.getDetailByNoticeId(this.lastClickOrderId)
          })
        }
        console.log(res.result)
      })
    },

    //根据二维码查询出条码实体，
    getBarcodeEntityByCode(record) {
      let param = { barcode: record.barcode }
      console.log(record.id)
      getAction('/barcode/tslWmBarcode/queryByBarcode', param).then((res) => {
        if (res.success) {
          this.showBarcode(res.result.id)
        }
        console.log(res.result)
      })
    },
    showBarcode(id) {
      let token = store.getters.token
      let barcodeId = id
      console.log('预览')
      getAction(`/business/bussStoragePackage/getPrintViewData/${barcodeId}`).then((res) => {
        if (res.success) {
          console.log(res.result)
          let router = res.result[0]
          let templateStr = `${window._CONFIG['domianURL']}/jmreport/view/`
          // 根据 tab 的内容动态生成 src 地址
          let top = 20
          let left = 50
          let returnStr =
            templateStr +
            router.templateId +
            '?token=' +
            token +
            '&id=' +
            router.id +
            '&table=' +
            router.table +
            '&infoTable=' +
            router.infoTable
          window.open(
            returnStr,
            'WHM_BARCODEPRINT_Win',
            'height=600,width=800,top=' +
              top +
              ',left=' +
              left +
              ',toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no'
          )
        } else {
        }
      })
    },
    sanitizeHTML(html) {
      // 使用合适的库来清理 HTML 内容，例如 DOMPurify
      // return DOMPurify.sanitize(html);
      const div = document.createElement('div')
      div.innerHTML = html

      // 遍历并移除可能不安全的标签或属性
      const allowedTags = ['b', 'i', 'u', 'em', 'strong', 'a', 'br']
      const elements = div.getElementsByTagName('*')

      for (let i = elements.length - 1; i >= 0; i--) {
        const el = elements[i]
        if (!allowedTags.includes(el.tagName.toLowerCase())) {
          el.parentNode.removeChild(el)
        }
      }

      return div.innerHTML
    },
    retract(record) {
      // this.confirmLoading = true
      // if(record.status == 2){
      //   //
      //
      // }else{
      getAction('/business/bussStoragePackage/retract', { id: record.id })
        .then((res) => {
          if (res.code === 200) {
            this.loadData()
          } else {
            this.$message.error(res.message)
          }
        })
        .catch((res) => {
          this.$message.error(res.message)
        })
        .finally(() => {
          // this.confirmLoading = false
        })
      // }
    },
    onRadioChange() {
      this.loadData()
    },
    changeDate() {
      this.$forceUpdate() // 强制刷新，解决日期更改后不刷新问题
    },
    onCustomRow(record) {
      return {
        onClick: () => {
          console.log('单击行:', record) // 验证方法是否被调用
          // 这里添加您的单击行处理逻辑
        },
      }
    },
    rowProperties(record, index) {
      return {
        on: {
          click: (event) => {
            // alert(888888)
          },
        },
        // onClick: (event) => {
        //   alert(888888)
        // },
      }
    },
    orderRowProperties(record, index) {
      return {
        on: {
          click: (event) => {
            console.log(record)
            this.lastClickOrderId = record.id
            this.getDetailByNoticeId(record.id)
          },
        },
        // onClick: (event) => {
        //   alert(888888)
        // },
      }
    },
    //获取入库详情
    getDetailByNoticeId(id) {
      let params = { id: id }
      this.noticeDetailsTable.dataSource = []
      getAction(this.url.bussStoragePackageMaterial.list, params).then((res) => {
        this.noticeDetailsTable.dataSource = res.result
        console.log('---------------------')
        console.log(res.result)
      })
    },
    reverseCheck() {
      if (this.selectionRows.length < 1) {
        this.$message.error('请选择后再进行撤销审核操作')
        return
      }
      if (this.selectionRows.length > 1) {
        this.$message.error('撤销审核最多只能选择一条记录')
        return
      }
      getAction('/business/bussStoragePackage/reverseCheck', { id: this.selectionRows[0].id }).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.error(res.message)
        }
      })
    },
    handleDelete: function (id) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { id: id }).then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    searchQueryTab1() {
      let searchVar = this.ext
      if (!searchVar) {
        this.loadProcData()
      }
    },
    // searchQueryTab() {
    //   this.dataSource = this.dataSourceBack
    //   let searchVar = this.ext1
    //   let newDataSource = []
    //   if (searchVar && searchVar != '') {
    //     this.dataSource.forEach(obj => {
    //       let newObj = {}
    //       let shouldAdd = false
    //       Object.keys(obj).forEach(key => {
    //         if (typeof obj[key] === 'string' && obj[key].includes(searchVar)) {
    //           newObj[key] = obj[key].replace(new RegExp(`(${searchVar})`, 'g'), '<span class="highlight">$1</span>')
    //           shouldAdd = true // Set flag to true if any property meets criteria
    //         } else {
    //           newObj[key] = obj[key]
    //         }
    //       })
    //       if (shouldAdd) {
    //         newDataSource.push(newObj)
    //       }
    //     })
    //     this.dataSource = newDataSource
    //   }
    // },
    getProcQueryParams() {
      //获取查询条件
      var param = {}
      var param = Object.assign({}, {}, {}, {})
      console.log('canshu', param)
      param.field = this.getTable1QueryField()
      param.ext = this.ext
      param.pageNo = this.table1.ipagination.current
      param.pageSize = this.table1.ipagination.pageSize
      ;(param.status = 999), 2
      // param.procurementType = 0
      return filterObj(param)
    },
    getTable1QueryField() {
      //TODO 字段权限控制
      var str = 'id,'
      this.table1.columns.forEach(function (value) {
        str += ',' + value.dataIndex
      })
      return str
    },
    loadProcData() {
      //加载数据 若传入参数1则加载第一页的内容
      // if (arg === 1) {
      //   this.ipagination.current = 1;
      // }
      // var params = {}
      var params = this.getProcQueryParams() //查询条件
      console.log('初始加载入参' + params)
      this.table1.loading = true
      getAction(this.url.proclist, params)
        .then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.table1.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.table1.ipagination.total = res.result.total
            } else {
              this.table1.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.table1.loading = false
        })
    },
    onSelectChangeTab1(selectedRowKeys, selectionRows) {
      this.table1.selectedRowKeys = selectedRowKeys
      this.table1.selectionRows = selectionRows
      console.log('--------------选中')
    },
    handleAdd: function () {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
      this.$nextTick(() => {
        this.$refs.modalForm.$refs.realForm.containDelete = this.containDelete
      })
    },
    addNotice() {
      const rows = this.table1.selectionRows
      if (rows.length == 0) {
        this.$message.warn('请选择采购单！')
        return
      }
      console.log(rows[0])
      if (rows.arrivalNum == null) {
        rows.arrivalNum = 0
      }
      if (rows[0].procurementNum == rows[0].arrivalNum) {
        this.$message.warn('该采购单已被使用！')
        return
      }

      const supplierId = rows[0].supplierId
      const newrows = rows.filter((item) => item.supplierId === supplierId)
      if (newrows.length != rows.length) {
        this.$message.warn('一个入库通知单单只能是同一个供应商！')
        return
      }
      //
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
      // 添加入库通知单
      this.$nextTick(() => {
        this.$refs.modalForm.$refs.realForm.containDelete = this.containDelete

        this.$refs.modalForm.$refs.realForm.procSelectRows = rows
        this.$refs.modalForm.$refs.realForm.addProc()
      })
    },
    handleChangeTab() {
      switch (this.activeKey) {
        case 'cg':
          this.containDelete = true
          break
        case 'rk':
          this.containDelete = false
          break
        default:
          break
      }
    },
    batchDel: function () {
      if (!this.url.deleteBatch) {
        this.$message.error('请设置url.deleteBatch属性!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectionRows[a].detailId + ','
        }
        var that = this
        this.$confirm({
          title: '确认删除',
          content: '是否删除选中数据?',
          onOk: function () {
            that.loading = true
            deleteAction(that.url.deleteBatch, { ids: ids })
              .then((res) => {
                if (res.success) {
                  //重新计算分页问题
                  that.reCalculatePage(that.selectedRowKeys.length)
                  that.$message.success(res.message)
                  that.loadData()
                  that.onClearSelected()
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.loading = false
              })
          },
        })
      }
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'code', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'type', text: '单据类型', dictCode: '' })
      fieldList.push({ type: 'string', value: 'lotNumber', text: '批次号', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'factoryTime', text: '进厂日期' })
      fieldList.push({ type: 'string', value: 'venderId', text: '供应商', dictCode: '' })
      fieldList.push({ type: 'string', value: 'procurementId', text: '采购id', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style>
.highlight {
  color: red;
}

@import '~@assets/less/common.less';
.qc {
  /*color: gray;*/
  background-color: red; /* 灰色背景 */
}

.ant-table {
  line-height: 1.08;
}
.ant-table table {
  line-height: 1.08;
}

.ant-table-tbody :deep(.table-striped) td {
  background-color: #fafafa;
}

.ant-table-thead tr,
.ant-table-thead th {
  border: 1px solid #666666; /* 深灰色边框 */
}

/* 加深边框颜色 */
.ant-table-tbody tr,
.ant-table-tbody td {
  border: 1px solid #666666; /* 深灰色边框 */
}

/* .ant-table-bordered .ant-table-tbody > tr > td
 {
  border-right:1px solid red;
 } */

.ant-table-thead > tr:first-child > th:last-child {
  border-right: 1px solid black;
}
.ant-table-bordered .ant-table-tbody > tr > td:last-child {
  border-right: 1px solid black;
}

.ant-table-bordered .ant-table-tbody > tr:last-child > td {
  border-bottom: 1px solid black;
}

.ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  padding: 8px 8px;
}
/* 表格内容的padding是8px */
/* .ant-table-tbody .ant-table-row td {
    padding-top: 8px;
    padding-bottom: 8px;
} */
.ant-table-tbody > tr > td.colHidden {
  display: none;
}
</style>